package com.example.fw;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class HelperWithWebDriverBase extends HelperBase {
	
	private WebDriver driver;
	
	public HelperWithWebDriverBase(ApplicationManager manager){
		super(manager);
		driver = manager.getDriver();
	}

	protected void type(By locator, String name) {
		driver.findElement(locator).clear();
		driver.findElement(locator).sendKeys(name);
	}
	
	protected void select(By locator, int index) {
		new Select(driver.findElement(locator)).selectByIndex(index);
	}

	protected WebElement findElement(By name) {
		try {
		return driver.findElement(name);
		} catch (Exception e) {
			return null;
		}
	}
	
	protected List<WebElement> findElements(By name) {
		return driver.findElements(name);
	}

	protected void openUrl(String string) {
		driver.get(manager.getProperty("baseUrl") + string);
	}
	
		
	protected void openAbsoluteUrl(String string) {
		driver.get(string);
	}

	protected void click(By name) {
		findElement(name).click();
	}

}
